import api from '../../api';
import { message } from 'antd';
export default {
  namespace: 'stressTestReportConfirmM',
  state: {},
  effects: {
    //获取报告列表
    *getDataList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressTestReportConfirm.getDataList, payload);
      if (res && res.code == 0) {
        callback(res.data);
      } else {
        callback(false);
        message.error(res?.msg || '查询报告确认列表失败!');
      }
    },

    //报告申请确认
    *confimApply({ payload, callback }, { call, put }) {
      const res = yield call(api.stressTestReportConfirm.saveApply, payload);
      if (res && res.code == 0) {
        callback(true);
        message.success('报告申请成功!');
      } else if (res && res.code == 6) {
        callback(true);
        message.warning(res.msg);
      } else {
        callback(false);
        if (payload.managerInfosForReport.length > 1) {
          message.error('批量报告申请失败：' + res.msg);
        } else {
          message.error('报告申请失败：' + res.msg);
        }
      }
    },
    //报告批量确认
    *confirmList({ payload, callback }, { call, put }) {
      const res = yield call(api.stressTestReportConfirm.confirmList, payload);
      if (res && res.code == 0) {
        callback(true);
        message.success('报告确认成功!');
      } else {
        callback(false);
        message.error(res?.msg || '报告确认失败!');
      }
    },
    //单个报告删除
    *deleteSingle({ payload, callback }, { call, put }) {
      let res = yield call(api.stressTestReportConfirm.deleteSingleBymaat, payload);
      if (res && res.code == 0) {
        callback(true);
      } else {
        callback(false);
        message.error(res?.msg || '报告删除失败!');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
